package com.cn.onetrip.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.cn.onetrip.activity.R;
import com.cn.onetrip.objects.InfosListObj;
import com.cn.onetrip.objects.TipsType;
import com.cn.onetrip.untility.SysApplication;

public class InfoItemAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private Context mContext;
	private ListView mListView;
	private Handler mhandler;
	private List<InfosListObj> tipsList = new ArrayList<InfosListObj>();

	public InfoItemAdapter(Context context, ListView listView, Handler handler) {
		mInflater = LayoutInflater.from(context);
		mContext = context;
		mListView = listView;
		mhandler = handler;
		
		tipsList = SysApplication.infosMapList.get("tips");
		if (tipsList.get(tipsList.size()-1).tip_type_cd != TipsType.travels) {
			InfosListObj objTravel = new InfosListObj();
			objTravel.tip_type_cd = TipsType.travels;
			objTravel.title = context.getResources().getString(R.string.info_travels);
			tipsList.add(objTravel);
		}
	}

	@Override
	public int getCount() {
		return tipsList.size();
	}

	@Override
	public Object getItem(int position) {
		if (position >= getCount()) {
			return null;
		}
		return tipsList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		InfosListObj model = tipsList.get(position);
		convertView = mInflater.inflate(R.layout.info_list_items, null);
		convertView.setTag(position);
		ImageView info_icon = (ImageView) convertView
				.findViewById(R.id.InfoItemIcon);
		TextView titleText = (TextView) convertView
				.findViewById(R.id.InfoItemTitle);
		int drawableID;
		switch (model.tip_type_cd) {
		case TipsType.tickets:
			drawableID = mContext.getResources().getIdentifier(
					"info_icon_tickets", "drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
		case TipsType.traffic:
			drawableID = mContext.getResources().getIdentifier(
					"info_icon_traffic", "drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
		case TipsType.todo:
			drawableID = mContext.getResources().getIdentifier(
					"info_icon_todo", "drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
		case TipsType.consume:
			drawableID = mContext.getResources().getIdentifier(
					"info_icon_consume", "drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
		case TipsType.arm:
			drawableID = mContext.getResources().getIdentifier("info_icon_arm",
					"drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
		case TipsType.feast:
			drawableID = mContext.getResources().getIdentifier(
					"info_icon_feast", "drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
		case TipsType.way:
			drawableID = mContext.getResources().getIdentifier("info_icon_way",
					"drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
		case TipsType.alert:
			drawableID = mContext.getResources().getIdentifier(
					"info_icon_alert", "drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
		case TipsType.tips:
			drawableID = mContext.getResources().getIdentifier(
					"info_icon_tips", "drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;
			
		case TipsType.travels:
			drawableID = mContext.getResources().getIdentifier(
					"info_icon_travel", "drawable",
					mContext.getApplicationContext().getPackageName());
			info_icon.setBackgroundResource(drawableID);
			break;

		default:
			break;
		}

		titleText.setText(model.title);

		return convertView;
	}

}
